<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>个性化旅游系统</title>
    <style>
        body {
            font-family: 'Microsoft YaHei', sans-serif;
            background-color: #f5f5f5;
            display: flex;
            justify-content: center;
            align-items: center;
            height: 100vh;
            margin: 0;
        }
        .container {
            background-color: white;
            border-radius: 10px;
            box-shadow: 0 10px 25px rgba(0, 0, 0, 0.1);
            width: 400px;
            padding: 30px;
            text-align: center;
        }
        h1 {
            color: #3498db;
            margin-bottom: 30px;
        }
        .btn-container {
            display: flex;
            justify-content: space-around;
            margin-top: 30px;
        }
        .btn {
            background-color: #3498db;
            color: white;
            border: none;
            padding: 10px 20px;
            border-radius: 5px;
            cursor: pointer;
            font-size: 16px;
            transition: background-color 0.3s;
        }
        .btn:hover {
            background-color: #2980b9;
        }
    </style>
</head>
<body>
    <div class="container" id="main-container">
        <h1>欢迎使用个性化旅游系统</h1>
        <div class="btn-container">
            <button class="btn" onclick="showLoginForm()">登录</button>
            <button class="btn" onclick="showRegisterForm()">注册</button>
        </div>
    </div>

    <script>
        function showLoginForm() {
            var html = "<h1>用户登录</h1>";
            html += "<form id=\"login-form\">";
            html += "    <div style=\"margin-bottom: 15px;\">";
            html += "        <input type=\"text\" id=\"username\" placeholder=\"用户名\" style=\"width: 100%; padding: 10px; border-radius: 5px; border: 1px solid #ddd;\">";
            html += "    </div>";
            html += "    <div style=\"margin-bottom: 20px;\">";
            html += "        <input type=\"password\" id=\"password\" placeholder=\"密码\" style=\"width: 100%; padding: 10px; border-radius: 5px; border: 1px solid #ddd;\">";
            html += "    </div>";
            html += "    <div id=\"login-message\" style=\"color: red; margin-bottom: 10px;\"></div>";
            html += "    <div class=\"btn-container\">";
            html += "        <button type=\"button\" class=\"btn\" style=\"background-color: #95a5a6;\" onclick=\"location.reload()\">返回</button>";
            html += "        <button type=\"button\" class=\"btn\" onclick=\"login()\">登录</button>";
            html += "    </div>";
            html += "</form>";
            document.getElementById('main-container').innerHTML = html;
        }

        function showRegisterForm() {
            var html = "<h1>用户注册</h1>";
            html += "<form id=\"register-form\">";
            html += "    <div style=\"margin-bottom: 15px;\">";
            html += "        <input type=\"text\" id=\"reg-username\" placeholder=\"用户名\" style=\"width: 100%; padding: 10px; border-radius: 5px; border: 1px solid #ddd;\">";
            html += "    </div>";
            html += "    <div style=\"margin-bottom: 15px;\">";
            html += "        <input type=\"password\" id=\"reg-password\" placeholder=\"密码\" style=\"width: 100%; padding: 10px; border-radius: 5px; border: 1px solid #ddd;\">";
            html += "    </div>";
            html += "    <div style=\"margin-bottom: 20px;\">";
            html += "        <input type=\"password\" id=\"reg-confirm-password\" placeholder=\"确认密码\" style=\"width: 100%; padding: 10px; border-radius: 5px; border: 1px solid #ddd;\">";
            html += "    </div>";
            html += "    <div id=\"register-message\" style=\"color: red; margin-bottom: 10px;\"></div>";
            html += "    <div class=\"btn-container\">";
            html += "        <button type=\"button\" class=\"btn\" style=\"background-color: #95a5a6;\" onclick=\"location.reload()\">返回</button>";
            html += "        <button type=\"button\" class=\"btn\" onclick=\"register()\">注册</button>";
            html += "    </div>";
            html += "</form>";
            document.getElementById('main-container').innerHTML = html;
        }

        function login() {
            const username = document.getElementById('username').value;
            const password = document.getElementById('password').value;
            
            if (!username || !password) {
                document.getElementById('login-message').innerText = '用户名和密码不能为空';
                return;
            }
            
            fetch('/login', {
                method: 'POST',
                headers: {
                    'Content-Type': 'application/json',
                },
                body: JSON.stringify({ username, password }),
            })
            .then(response => response.json())
            .then(data => {
                if (data.success) {
                    window.location.href = '/dashboard';
                } else {
                    document.getElementById('login-message').innerText = data.message || '用户名或密码错误';
                }
            })
            .catch(error => {
                document.getElementById('login-message').innerText = '登录失败，请稍后再试';
                console.error('Error:', error);
            });
        }

        function register() {
            const username = document.getElementById('reg-username').value;
            const password = document.getElementById('reg-password').value;
            const confirmPassword = document.getElementById('reg-confirm-password').value;
            
            if (!username || !password) {
                document.getElementById('register-message').innerText = '用户名和密码不能为空';
                return;
            }
            
            if (password !== confirmPassword) {
                document.getElementById('register-message').innerText = '两次输入的密码不一致';
                return;
            }
            
            fetch('/register', {
                method: 'POST',
                headers: {
                    'Content-Type': 'application/json',
                },
                body: JSON.stringify({ username, password }),
            })
            .then(response => response.json())
            .then(data => {
                if (data.success) {
                    document.getElementById('register-message').style.color = 'green';
                    document.getElementById('register-message').innerText = '注册成功，即将跳转到登录页面';
                    setTimeout(() => {
                        showLoginForm();
                    }, 2000);
                } else {
                    document.getElementById('register-message').innerText = data.message || '注册失败';
                }
            })
            .catch(error => {
                document.getElementById('register-message').innerText = '注册失败，请稍后再试';
                console.error('Error:', error);
            });
        }
    </script>
</body>
</html> 